﻿using System.Linq;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;
namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// Room Repository
    /// </summary>
    public class RoomRepository : IRoomRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get Room Details by Title
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<Room> FindRoomByName(string strQuery)
        {
            return _db.Rooms.Where(d => d.RoomName.Contains(strQuery));
        }

        /// <summary>
        /// Get All Rooms
        /// </summary>
        /// <returns></returns>
        public IQueryable<Room> FindAllRooms()
        {
            return _db.Rooms;
        }

        /// <summary>
        /// Get Room by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Room GetRoomById(int id)
        {
            return _db.Rooms.SingleOrDefault(d => d.RoomId == id);
        }

        /// <summary>
        /// Add Room in the Database
        /// </summary>
        /// <param name="room"></param>
        public void Add(Room room)
        {
            _db.Rooms.AddObject(room);
        }

        /// <summary>
        /// Delete Room from Database
        /// </summary>
        /// <param name="room"></param>
        public void Delete(Room room)
        {
            _db.Rooms.DeleteObject(room);
        }

        /// <summary>
        /// Save News/Event in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }
    }
}